<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>作业1</title>
</head>

<body>
    <script>
        let arr = []
        let age
        for (i = 1; i <= 5; i++) {
            age = + prompt(`请输入第${i}个年龄`)
            // NaN 特性：不等于自身
            if (age !== age || age < 0 || age > 100) {
                continue
            }
            arr[i - 1] = age
        }
        let chengnian = [], sum = 0, max = arr[0], min = arr[0]
        for (j = 0; j < arr.length; j++) {
            if (arr[j] >= 18) {
                chengnian.push(arr[j])
            }
            if (arr[j] > max) {
                max = arr[j]
            }

            if (arr[j] < min) {
                min = arr[j]
            }
            sum += arr[j]
        }
        console.log(`成年的年龄有${chengnian}`)
        console.log(`所有人总年龄为${sum}`)
        console.log(`所有人的平均年龄为${sum / arr.length}`)
        console.log(`最大年龄是${max}，最小年龄是${min}`)
    </script>
</body>

</html>